package com.sims.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.BeanUtils;

import com.sims.bean.Material;
import com.sims.dao.IMaterialDAO;
import com.sims.util.Constant;

public class MaterialService {
	IMaterialDAO materialDAO;
	
	public Map<String, String> findMaterialByScope(Material material, List materialList) {
		Map<String, String> result = new HashMap<String, String>();
		
		String scope = material.getScope();
		materialList = materialDAO.findByScope(scope); //数据库里的空格也许会引起无法正确匹配
		
		result.put(Constant.SUCCESS, null);
		return result;
	}
	
	public Map<String, String> downloadMaterial(Material material) {
		Map<String, String> result = new HashMap<String, String>();
		
		Material m = materialDAO.findById(material.getMid());
		
		BeanUtils.copyProperties(m, material);
		
		result.put(Constant.SUCCESS, null);
		return result;
	}
	
	public Map<String, String> addMaterial(Material material) {
		Map<String, String> result = new HashMap<String, String>();
		
		materialDAO.attachDirty(material);
		
		result.put(Constant.SUCCESS, null);
		return result;
	}
	
	public Map<String, String> deleteMaterial(Material material) {
		Map<String, String> result = new HashMap<String, String>();
		
		Material m = materialDAO.findById(material.getMid());
		materialDAO.delete(m);
		
		result.put(Constant.SUCCESS, null);
		return result;
	}
}
